<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler'>
      <f-search-form-item label='订单日期' type='range' name='beginDate' />
      <f-search-form-item label='部门' ref='dept' name='deptId' type='select' :data='api.hyorder.deptList' valueKey='deptId' label-key='deptName' />
      <f-search-form-item label='订单编号' name='orderNo' />
      <f-search-form-item label='客户名称' name='customName' slot='advanced' />
      <f-search-form-item label='业务员' name='saleManName' slot='advanced' />
      <f-search-form-item label='制单人' name='nickName' slot='advanced' />
    </f-search-form>
    <f-table ref='table' rowKey='orderId' 
             :columns='columns'
             :scroll='{x:true}' 
             :multiple='false' 
             :operator='operator' 
             :params='queryParam' 
             :api='api.hyorder' 
             handler='hyCalculateOrderTab2ListHandler'>
        <span slot='sendType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text==1'>现款</a-tag>
            <a-tag color='#FF0000' v-if='text==2'>预收款</a-tag>
            <a-tag color='#87d068' v-if='text==3'>资保金</a-tag>
            <a-tag color='purple' v-if='text==4'>全额资信</a-tag>
        </span>
      <span slot='deptType' slot-scope='text, record, index'>
        <a-tag color='#87d068' v-if='text=="ZS"'>招商</a-tag>
        <a-tag color='#108ee9' v-if='text=="ZY"'>自营</a-tag>
      </span>
      <span slot='calculateState' slot-scope='text, record, index'>
            <a-tag color='pink' v-if='text==0'>未提交</a-tag>
            <a-tag color='#87d068' v-if='text==1' @click='processImg(record,record.applyIncId)'>{{ record.taskName }}</a-tag>
            <a-tag color='#f50' v-if='text==2'>已审批</a-tag>
        </span>
      <span slot='action' slot-scope='text, record'>
          <template>
             <a href='javascript:;' @click='$refs.caclulateDrawer.showDrawer(record)'>详情</a>
             <a-divider type='vertical' v-if='record.taskDefinitionKey=="__initiator__"'/>
            <a @click='completeTask(record)' v-if='record.taskDefinitionKey=="__initiator__"'>提交</a>
          </template>
            <a-divider type='vertical' />
         <a-dropdown>
             <a class='ant-dropdown-link'>更多<a-icon type='down' /></a>
             <a-menu slot='overlay'>
               <a-menu-item v-if='record.calculateState!=0 && (record.taskName=="销售服务部部长审批"|| record.taskName=="开票员制单")'>
                  <a href='javascript:;' @click='deleteProcessInstance(record.applyIncId,"hyCalculateProcDeleteHandler")'>撤销申请</a>
               </a-menu-item>
               <a-menu-item>
                <a href='javascript:;' @click='syncOrderReturn(record)'>同步到待回款</a>
               </a-menu-item>
             </a-menu>
         </a-dropdown>
        </span>
    </f-table>
    <caclulate-apply-drawer ref='caclulateDrawer'></caclulate-apply-drawer>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
  </div>
</template>
<script>
import api from "../../../js/api"
import { processMixins } from "@/core/mixins/processMixins"
import CaclulateApplyDrawer from "./components/caclulate_apply_drawer"
import ProcessImage from "../../../../flowable/process/process_image"

export default {
  name: "Tab2",
  components: { CaclulateApplyDrawer, ProcessImage },
  mixins: [processMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      activeKey: "0",
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "订单编号",
          align: "left",
          width: "110px",
          dataIndex: "orderNo"
        },
        {
          title: "发货日期",
          align: "left",
          width: "120px",
          dataIndex: "sendDate"
        },
        {
          title: "部门",
          align: "left",
          width: "120px",
          dataIndex: "deptName"
        },

        {
          title: "业务类型",
          align: "left",
          width: "80px",
          dataIndex: "deptType",
          scopedSlots: { customRender: "deptType" }
        },
        {
          title: "区域",
          align: "left",
          width: "80px",
          dataIndex: "businessArea"
        },
        {
          title: "单位名称",
          align: "left",
          ellipsis: true,
          width: "130px",
          dataIndex: "customName"
        },
        {
          title: "业务员",
          align: "left",
          width: "120px",
          dataIndex: "saleManName"
        },
        {
          title: "业务编码",
          align: "left",
          width: "120px",
          dataIndex: "businessCode"
        },
        {
          title: "发货方式",
          align: "left",
          dataIndex: "sendType",
          width: "120px",
          scopedSlots: { customRender: "sendType" }
        },
        {
          title: "创建日期",
          dataIndex: "createTime",
          width: 150,
          sorter: true
        },
        {
          title: "开票员",
          align: "center",
          fixed: "right",
          dataIndex: "nickName"
        },
        {
          title: "核算状态",
          align: "left",
          width: "150px",
          fixed: "right",
          dataIndex: "calculateState",
          scopedSlots: { customRender: "calculateState" }
        },
        {
          title: "操作",
          align: "center",
          width: "140px",
          dataIndex: "action",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator,
      processImageVisible: false,
      processInstanceId: null
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    //同步订单明细到回款表
    syncOrderReturn(order) {
      this.http.confirm(this, {
        content: "确认同步订单明细到回款表吗?",
        url: api.hyorder.syncOrderReturn,
        data: {
          orderId: order.orderId
        },
        success: (me, data) => {
          this.$refs.table.refresh()
        }
      })
    },
    changeHandler(activeKey) {
      this.activeKey = activeKey
      this.$refs.table.refresh(true, { activeKey: this.activeKey })
    }
  }
}
</script>
